﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Syspetro.Core.Extensions
{
    public static class RandomGenerater
    {
        private const string letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
        /// <summary>
        /// 产生英文字符加数字随机字符
        /// </summary>
        /// <param name="length"></param>
        /// <param name="toLower"></param>
        /// <returns></returns>
        public static string Characters(int length = 6, bool toLower = false)
        {
            if (length < 1)
                return string.Empty;

            var random = new Random(Guid.NewGuid().GetHashCode());

            var chars = new char[length];

            for (int i = 0; i < length; i++)
            {
                chars[i] = letters[random.Next(0, letters.Length - 1)];
            }
            if (toLower)
                return new string(chars).ToLower();
            return new string(chars);
        }

        public static int Number(int minValue = 0, int maxValue = int.MaxValue)
        {
            var random = new Random(Guid.NewGuid().GetHashCode());

            return random.Next(minValue, maxValue);
        }
        /// <summary>
        /// 产生数字随机字符
        /// </summary>
        /// <param name="length"></param>
        /// <returns></returns>
        public static string Captcha(int length = 6)
        {
            var random = new Random(Guid.NewGuid().GetHashCode());

            return random.Next(1000, 999999).ToString("D" + length);
        }
    }
}
